
*******************
*** Main tables ***
*******************

*** Table 1 - summary statistics clicks and refugees ***

use "final_datasetoutliers.dta", clear

latabstat views norviews refugees refugeesABO refugeesEBO ratio_refugees, s(mean sd med n) format(%9.3f)///
columns(statistics) tf(table1) replace caption(Summary statistics - clicks and refugees)

use "final_dataset.dta", clear

latabstat views norviews, s(mean sd med n) format(%9.3f) columns(statistics) ///
tf(table1) append

use "final_dataset_classified.dta", clear

latabstat views norviews if flyktingar==1, s(mean sd med n) format(%9.3f) columns(statistics) ///
tf(table1) append

latabstat views norviews if flyktingar==0, s(mean sd med n) format(%9.3f) columns(statistics) ///
tf(table1) append


*** Table 2 - clicks and refugees - all refugee articles ***

use "final_dataset.dta", clear

** Panel A: OLS estimates **

* OLS 
reg norviews ratio_refugees, vce(cluster id)
outreg2 using "table2.tex", title (Panel A: OLS estimates) ctitle(" ") nocon noobs noni nor2 ///
addtext(Municipality FE, - , Month FE, - , Linear time trend, - ) ///
addstat(N,  e(N), R$^2$,  e(r2)) replace

* fixed effects
reg norviews ratio_refugees i.pubmonth, vce(cluster id)
outreg2 using "table2.tex", keep(ratio_refugees) ctitle(" ") nocon noobs noni nor2 ///
addtext(Municipality FE, - ,Month FE, \checkmark ,Linear time trend, - ) ///
addstat(N,  e(N), R$^2$,  e(r2)) append

xtreg norviews ratio_refugees, fe vce(cluster id)
outreg2 using "table2.tex", ctitle(" ") nocon noobs noni nor2 ///
addtext(Municipality FE, \checkmark , Month FE, -, Linear time trend, -) ///
addstat(N,  e(N), R$^2$,  e(r2_o)) append

xtreg norviews ratio_refugees i.pubmonth,fe vce(cluster id)
outreg2 using "table2.tex", keep(ratio_refugees) ctitle(" ") nocon noobs noni nor2 ///
addtext(Municipality FE, \checkmark ,Month FE, \checkmark, Linear time trend, -) ///
addstat(N,  e(N), R$^2$,  e(r2_o)) append

* linear trend
xtreg norviews ratio_refugees trend,fe vce(cluster id)
outreg2 using "table2.tex", keep(ratio_refugees) ctitle(" ") nocon noobs noni nor2 ///
addtext(Municipality FE, \checkmark ,Month FE, - ,Linear time trend, \checkmark) ///
addstat(N,  e(N), R$^2$,  e(r2_o)) append

* log 
xtreg lnorviews lratiorefugees i.pubmonth, fe vce(cluster id)
outreg2 using "table2.tex", keep(lratiorefugees)  ctitle(" ") nocon noobs noni nor2 ///
addtext(Municipality FE, \checkmark , Month FE, \checkmark ,Linear time trend, -) ///
addstat(N,  e(N), R$^2$,  e(r2_o)) append

** Panel B: 2SLS estimates **

xtivreg norviews (ratio_refugees=housingpc),fe vce(cluster id) first 
outreg2 using "table2b.tex", title (Panel B: 2SLS estimates) keep(ratio_refugees housingpc) ///
addtext(Municipality FE, \checkmark , Month FE, - ,Linear time trend, -) ///
nocon noobs noni nor2 ctitle(" ")  replace

xtivreg norviews i.pubmonth (ratio_refugees=housingpc),fe vce(cluster id) first
outreg2 using "table2b.tex", keep(ratio_refugees) ///
addtext(Municipality FE, \checkmark , Month FE, \checkmark ,Linear time trend, -) ///
nocon noobs noni nor2 ctitle(" ") append

xtivreg norviews trend (ratio_refugees=housingpc),fe vce(cluster id) first
outreg2 using "table2b.tex", keep(ratio_refugees) ///
addtext(Municipality FE, \checkmark , Month FE, - ,Linear time trend, \checkmark) ///
nocon noobs noni nor2 ctitle(" ")  append

** Panel C: First stage estimates **

xtreg ratio_refugees housingpc,fe vce(cluster id) 
outreg2 using "table2c.tex", title (Panel C: First stage estimates) keep(housingpc) ///
addtext(Municipality FE, \checkmark , Month FE, - ,Linear time trend, -) ///
nocon noobs noni nor2 ctitle(" ") ///
addstat(N,  e(N), R$^2$,  e(r2_o), F - statistics, e(F)) replace

xtreg ratio_refugees i.pubmonth housingpc,fe vce(cluster id) 
outreg2 using "table2c.tex", keep(housingpc) ///
addtext(Municipality FE, \checkmark , Month FE, \checkmark ,Linear time trend, -) ///
nocon noobs noni nor2 ctitle(" ") ///
addstat(N,  e(N), R$^2$,  e(r2_o), F - statistics, e(F)) append

xtreg ratio_refugees trend housingpc,fe vce(cluster id) 
outreg2 using "table2c.tex", keep(housingpc) ///
addtext(Municipality FE, \checkmark , Month FE, - ,Linear time trend, \checkmark) ///
nocon noobs noni nor2 ctitle(" ") ///
addstat(N,  e(N), R$^2$,  e(r2_o), F - statistics, e(F)) append


*** Table 3 - Clicks and refugees - empathic articles ***

use "final_dataset_classified.dta", clear

* All sample
xi: reg norviews ratio_refugees flyktingar c.ratio_refugees#i.flyktingar i.id i.pubmonth, vce(cluster id)
outreg2 using "table3.tex",  keep(ratio_refugees flyktingar c.ratio_refugees#flyktingar) ///
addtext(Municipality FE, \checkmark , Month FE, \checkmark ) ///
nocon noobs noni nor2 ctitle(" ") ///
addstat(N,  e(N), R$^2$,  e(r2)) replace

* 2SLS all sample
gen inter=c.ratio_refugees#flyktingar
gen interIV=c.housingpc#flyktingar
xi: ivreg norviews flyktingar i.pubmonth i.id (ratio_refugees inter = housingpc interIV), cluster(id)
outreg2 using "table3.tex",  keep(ratio_refugees flyktingar inter) ///
addtext(Municipality FE, \checkmark , Month FE, \checkmark ) ///
nocon noobs noni nor2 ctitle(" ") ///
addstat(N,  e(N), R$^2$,  e(r2)) append

* Subsample empathic articles
xi: reg norviews ratio_refugees i.id i.pubmonth if flyktingar==0, vce(cluster id)
outreg2 using "table3.tex",  keep(ratio_refugees) ///
addtext(Municipality FE, \checkmark , Month FE, \checkmark ) ///
nocon noobs noni nor2 ctitle(" ") ///
addstat(N,  e(N), R$^2$,  e(r2)) append

xi: reg norviews ratio_refugees i.id i.pubmonth if flyktingar==1, vce(cluster id)
outreg2 using "table3.tex",  keep(ratio_refugees) ///
addtext(Municipality FE, \checkmark , Month FE, \checkmark ) ///
nocon noobs noni nor2 ctitle(" ") ///
addstat(N,  e(N), R$^2$,  e(r2)) append

* 2SLS subsamples
xi: ivreg norviews i.id i.pubmonth (ratio_refugees=housingpc) if flyktingar==0, cluster(id) 
outreg2 using "table3.tex",  keep(ratio_refugees) ///
addtext(Municipality FE, \checkmark , Month FE, \checkmark ) ///
nocon noobs noni nor2 ctitle(" ") ///
addstat(N,  e(N), R$^2$,  e(r2)) append

xi: ivreg norviews i.id i.pubmonth (ratio_refugees=housingpc) if flyktingar==1, cluster(id) 
outreg2 using "table3.tex",  keep(ratio_refugees) ///
addtext(Municipality FE, \checkmark , Month FE, \checkmark ) ///
nocon noobs noni nor2 ctitle(" ") ///
addstat(N,  e(N), R$^2$,  e(r2)) append


* Ratio of empathic and non-empathic articles 
xi: reg ratio_emp ratio_refugees i.id i.pubmonth, vce(cluster id)
outreg2 using "table3.tex",  keep(ratio_refugees) ///
addtext(Municipality FE, \checkmark , Month FE, \checkmark ) ///
nocon noobs noni nor2 ctitle(" ") ///
addstat(N,  e(N), R$^2$,  e(r2)) append


*** Table 4 - Sweden vs. neighbouring countries ***

use "final_dataset.dta"

* OLS Sweden
xi: reg norviews ratio_refugees i.id i.pubmonth if destino==1, vce(cluster id)
outreg2 using "table4.tex", keep(ratio_refugees)  ///
addtext(Municipality FE, \checkmark , Month FE, \checkmark ) ///
nocon noobs noni nor2 ctitle(" ") ///
addstat(N,  e(N), R$^2$,  e(r2)) replace

* OLS Neighbours
xi: reg norviews ratio_refugees i.id i.pubmonth if destino==0, vce(cluster id)
outreg2 using "table4.tex", keep(ratio_refugees) ///
addtext(Municipality FE, \checkmark , Month FE, \checkmark ) ///
nocon noobs noni nor2 ctitle(" ") ///
addstat(N,  e(N), R$^2$,  e(r2)) append

* 2SLS Sweden and Neighbor
foreach i in 1 0{
xi: ivreg norviews i.id i.pubmonth (ratio_refugees=housingpc) if destino==`i', cluster(id)
outreg2 using "table4.tex", keep(ratio_refugees) ///
addtext(Municipality FE, \checkmark , Month FE, \checkmark ) ///
nocon noobs noni nor2 ctitle(" ") ///
addstat(N,  e(N), R$^2$,  e(r2)) append
}

*** Table 5 - Results of accommodation type ***

use "final_dataset.dta", clear

xtreg norviews ratio_refugeesABO i.pubmonth,fe vce(cluster id)
outreg2 using "table5.tex", keep(ratio_refugeesABO) replace

xtreg norviews ratio_refugeesEBO i.pubmonth,fe vce(cluster id)
outreg2 using "table5.tex", keep(ratio_refugeesEBO) append

use "final_dataset_classified.dta"

xi: reg norviews ratio_refugeesABO flyktingar c.ratio_refugeesABO#flyktingar i.id i.pubmonth, vce(cluster id)
outreg2 using "table5.tex", keep(ratio_refugeesABO flyktingar c.ratio_refugeesABO#flyktingar) append

gen inter=c.ratio_refugeesABO#flyktingar
xi: reg norviews ratio_refugeesABO flyktingar inter i.id i.pubmonth, vce(cluster id)
lincom _b[ratio_refugees]+_b[inter]

xi: reg norviews ratio_refugeesEBO flyktingar c.ratio_refugeesEBO#flyktingar i.id i.pubmonth, vce(cluster id)
outreg2 using "table5.tex", keep(ratio_refugeesEBO flyktingar c.ratio_refugeesEBO#flyktingar) append

drop inter
gen inter=c.ratio_refugeesEBO#flyktingar
xi: reg norviews ratio_refugeesEBO flyktingar inter i.id i.pubmonth, vce(cluster id)
lincom _b[ratio_refugees]+_b[inter]

*** Table 6 - Alternative classifications and Placebo tests ***

use "final_dataset_classified1.dta"

xi: reg norviews ratio_refugees sverige c.ratio_refugees#sverige i.id i.pubmonth, vce(cluster id)
outreg2 using "table6.tex", keep(ratio_refugees sverige c.ratio_refugees#sverige) replace

drop inter
gen inter=c.ratio_refugees#sverige
xi: reg norviews ratio_refugees sverige inter i.id i.pubmonth, vce(cluster id)
lincom _b[ratio_refugees]+_b[inter]

use "final_dataset_classified2.dta"

xi: reg norviews ratio_refugees wordrefugee c.ratio_refugees#wordrefugee i.id i.pubmonth, vce(cluster id)
outreg2 using "table6.tex", keep(ratio_refugees wordrefugee c.ratio_refugees#wordrefugee) append

drop inter
gen inter=c.ratio_refugees#wordrefugee
xi: reg norviews ratio_refugees wordrefugee inter i.id i.pubmonth, vce(cluster id)
lincom _b[ratio_refugees]+_b[inter]

* file available after signing non-disclosure agreement with DN
import excel "placeboparallel.xlsx", firstrow sheet(Sheet2) clear

xtreg placebo_norviews placebo_refugees i.pubmonth, fe vce(cluster id)
outreg2 using "table6.tex", keep(placebo_refugees) append

use "final_dataset_events.dta"

xi: reg norviews ratio_refugees i.id i.pubmonth, vce(cluster id)
outreg2 using "table6.tex", keep(ratio_refugees) append

use "final_dataset_accidents.dta"

xi: reg norviews ratio_refugees i.id i.pubmonth, vce(cluster id)
outreg2 using "table6.tex", keep(ratio_refugees) append






